package com.vi.hcnetsdk.simpleapp;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.PixelFormat;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;

import com.hikvision.netsdk.HCNetSDK;
import com.hikvision.netsdk.NET_DVR_PREVIEWINFO;
import com.vi.hcnetsdk.jna.HCNetSDKJNAInstance;

@SuppressLint("NewApi")
public class PlaySurfaceView extends SurfaceView implements SurfaceHolder.Callback {
    private final String TAG = "PlaySurfaceView";

    public int getM_iWidth() {
        return m_iWidth;
    }
    public void setM_iWidth(int m_iWidth) {
        this.m_iWidth = m_iWidth;
    }
    public int getM_iHeight() {
        return m_iHeight;
    }
    public void setM_iHeight(int m_iHeight) {
        this.m_iHeight = m_iHeight;
    }

    private int m_iHeight = 1;
    private int m_iWidth = 1;
    private SurfaceHolder mHolder;
    public boolean bCreate = false;


    public PlaySurfaceView(Context context, AttributeSet attrs) {
        super((Context) context,attrs);//Constructor that is called when inflating a view from XML
        // TODO Auto-generated constructor stub

        mHolder = this.getHolder();
        getHolder().addCallback(this);
    }

    public PlaySurfaceView(Context context, AttributeSet attrs, int defStyle) {
        super(context,attrs,defStyle);//Perform inflation from XML and apply a class-specific base style
        // TODO Auto-generated constructor stub
        mHolder = this.getHolder();
        getHolder().addCallback(this);
    }

    public PlaySurfaceView(MainActivity context) {
        super((Context) context);//Simple constructor to use when creating a view from code
        // TODO Auto-generated constructor stub

        mHolder = this.getHolder();
        getHolder().addCallback(this);
    }

    @Override
    public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
        // TODO Auto-generated method stub
        setZOrderOnTop(true);
        getHolder().setFormat(PixelFormat.TRANSLUCENT);

        System.out.println("surfaceChanged");
    }

    @Override
    public void surfaceCreated(SurfaceHolder arg0) {
        // TODO Auto-generated method stub
        bCreate = true;
        System.out.println("surfaceCreated");

    }

    @Override
    public void surfaceDestroyed(SurfaceHolder arg0) {
        // TODO Auto-generated method stub
        System.out.println("surfaceDestroyed");
        bCreate = false;

    }

    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.setMeasuredDimension(m_iWidth-1, m_iHeight-1);
    }

    public void setParam(int nScreenSize) {
        m_iWidth = nScreenSize / 2;
        m_iHeight = (m_iWidth * 3) / 4;
    }
}


